package com.atmc.controller;

import com.atmc.bean.Authority;
import com.atmc.bean.Rule;
import com.atmc.mapper.AuthorityMapper;
import com.atmc.service.RuleService;
import javafx.scene.input.MouseDragEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.jws.WebParam;
import java.util.List;

@Controller
public class AdminController {
    @Autowired
    RuleService ruleService;
    @Autowired
    AuthorityMapper authorityMapper;
    //返回管理员集合信息
    @RequestMapping("/admin/admin-list")
    public String toAdminlist(Model model) {
        List<Rule> list = ruleService.selectAll();
        model.addAttribute("msg",list);
        return "admin/admin-list";
    }

    @RequestMapping("/admin/admin-role")
    public String toAdminrole() {

        return "admin/admin-role";
    }

    @RequestMapping("/admin/admin-cate")
    public String toAdmincate() {
        return "admin/admin-cate";
    }
    //返回所以的账号权限信息
    @RequestMapping("/admin/admin-rule")
    public String toAdminrule(Model model) {
        List<Authority> list = authorityMapper.selectAll();
        model.addAttribute("msg",list);
        return "admin/admin-rule";
    }
    //查询一条账号权限信息
    @RequestMapping("/admin/selectOne")
    public String toselectOne(@RequestParam("acco_name")String acco_name,Model model){
        Authority list = authorityMapper.selectOne(acco_name);
        model.addAttribute("msg",list);
        return "admin/admin-rule";
    }
    //跳转到修改页面
    @RequestMapping("/toadminupdate/{acco_id}")
    public String toadminupdate(@PathVariable("acco_id")Integer acco_id, Model model){
        model.addAttribute("acco_id",acco_id);
//        model.addAttribute("acco_name",acco_name);
        return "admin/adminRuleUpdate";
    }
    //修改一条权限信息
    @RequestMapping("/admin/updaterule")
    public String toupdaterule(@RequestParam("acco_id")Integer acco_id,
                               @RequestParam("role")String role,
                               Model model){
        Authority authority=new Authority(acco_id,null,null,null,role);
        authorityMapper.updateOne(authority);
        List<Authority> list = authorityMapper.selectAll();
        model.addAttribute("msg",list);
        return "admin/admin-rule";
    }
}
